


*** compute SW F stats for multiple endogenous variables 

***Inputs: 
* $Data/GameUserWPdaily_norm.dta
* $Data/maxmindirectionsmonth_zip260.dta

***Outputs: 
* $Results/age_SWF.tex

	
	use $Data/GameUserWPdaily_norm.dta, clear
	
	gen month = month(date)

		
	gen zip2 = int( zip/10)
	
	merge m:1 zip2 month using $Data/maxmindirectionsmonth_zip260.dta
	
	keep if _merge ==3
	
	
	gen monthyear = mofd(date)

	gen highpm =  weighted_dailypm > 25 & weighted_dailypm<. 

	
	
	egen cut_winddirection = cut(median_closestwind), at(0(60)360)
	replace cut_winddirection = 0 if median_closestwind ==360

	
	
	gen maxzipwind = (cut_winddirection ==maxdirection )
	replace maxzipwind = . if maxdirection==.
	
	keep if maxzipwind<. 
	
	
		egen cut_temp = cut(weighted_temperature), at(-40(10)40)

		
	label variable highpm "Daily PM2.5 $>$ 25" 

	
	
 egen cut_age = cut(age_sig), at(20(10)81)

 replace cut_age = 70 if age> =80
 replace cut_age = 20 if age<20
	
	
	
	
	
	levelsof cut_age 
	local list = r(levels)
	
	
	
foreach x in `list'  {
	
	gen highpm_group`x' = highpm* (cut_age ==`x')
	
}









ivreghdfe highpm_group20 (highpm_group30 highpm_group40 highpm_group50 highpm_group60 highpm_group70  = c.maxzipwind#i.cut_age ) weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

predict pmgroup1hat 

gen pmresid1 = highpm_group20 - pmgroup1hat 

reghdfe pmresid1 c.maxzipwind#i.cut_age weighted_wind_speed weighted_precipitation, absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

test  20.cut_age#c.maxzipwind 30.cut_age#c.maxzipwind 40.cut_age#c.maxzipwind 50.cut_age#c.maxzipwind 60.cut_age#c.maxzipwind 70.cut_age#c.maxzipwind

scalar FSW2 = r(F)*r(df)/(r(df)-1)
di FSW2


drop pmgroup1hat pmresid1 







ivreghdfe highpm_group30 (  highpm_group20 highpm_group40 highpm_group50 highpm_group60 highpm_group70  = c.maxzipwind#i.cut_age ) weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

predict pmgroup1hat 

gen pmresid1 = highpm_group30 - pmgroup1hat 

reghdfe pmresid1 c.maxzipwind#i.cut_age weighted_wind_speed weighted_precipitation, absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

test  20.cut_age#c.maxzipwind 30.cut_age#c.maxzipwind 40.cut_age#c.maxzipwind 50.cut_age#c.maxzipwind 60.cut_age#c.maxzipwind 70.cut_age#c.maxzipwind

scalar FSW3 = r(F)*r(df)/(r(df)-1)
di FSW3


drop pmgroup1hat pmresid1 






ivreghdfe highpm_group40  (highpm_group20 highpm_group30 highpm_group50 highpm_group60 highpm_group70  = c.maxzipwind#i.cut_age ) weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

predict pmgroup1hat 

gen pmresid1 = highpm_group40 - pmgroup1hat 

reghdfe pmresid1 c.maxzipwind#i.cut_age weighted_wind_speed weighted_precipitation, absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

test  20.cut_age#c.maxzipwind 30.cut_age#c.maxzipwind 40.cut_age#c.maxzipwind 50.cut_age#c.maxzipwind 60.cut_age#c.maxzipwind 70.cut_age#c.maxzipwind

scalar FSW4 = r(F)*r(df)/(r(df)-1)
di FSW4


drop pmgroup1hat pmresid1 





ivreghdfe highpm_group50   (highpm_group20 highpm_group30 highpm_group40  highpm_group60 highpm_group70  = c.maxzipwind#i.cut_age ) weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

predict pmgroup1hat 

gen pmresid1 = highpm_group50 - pmgroup1hat 

reghdfe pmresid1 c.maxzipwind#i.cut_age weighted_wind_speed weighted_precipitation, absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

test 20.cut_age#c.maxzipwind 30.cut_age#c.maxzipwind 40.cut_age#c.maxzipwind 50.cut_age#c.maxzipwind 60.cut_age#c.maxzipwind 70.cut_age#c.maxzipwind

scalar FSW5 = r(F)*r(df)/(r(df)-1)
di FSW5


drop pmgroup1hat pmresid1 




ivreghdfe highpm_group60    ( highpm_group20 highpm_group30 highpm_group40  highpm_group50 highpm_group70  = c.maxzipwind#i.cut_age ) weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

predict pmgroup1hat 

gen pmresid1 = highpm_group60 - pmgroup1hat 

reghdfe pmresid1 c.maxzipwind#i.cut_age weighted_wind_speed weighted_precipitation, absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

test  20.cut_age#c.maxzipwind 30.cut_age#c.maxzipwind 40.cut_age#c.maxzipwind 50.cut_age#c.maxzipwind 60.cut_age#c.maxzipwind 70.cut_age#c.maxzipwind

scalar FSW6 = r(F)*r(df)/(r(df)-1)
di FSW6


drop pmgroup1hat pmresid1 






ivreghdfe highpm_group70 (highpm_group20 highpm_group30 highpm_group40  highpm_group50   highpm_group60    = c.maxzipwind#i.cut_age ) weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

predict pmgroup1hat 

gen pmresid1 = highpm_group70 - pmgroup1hat 

reghdfe pmresid1 c.maxzipwind#i.cut_age weighted_wind_speed weighted_precipitation, absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

test 20.cut_age#c.maxzipwind 30.cut_age#c.maxzipwind 40.cut_age#c.maxzipwind 50.cut_age#c.maxzipwind 60.cut_age#c.maxzipwind 70.cut_age#c.maxzipwind

scalar FSW7 = r(F)*r(df)/(r(df)-1)
di FSW7


drop pmgroup1hat pmresid1 











matrix Fstats = [FSW2, FSW3, FSW4, FSW5,FSW6 ,FSW7]'


estout matrix(Fstats) using $Results/age_SWF.tex, replace





